unit uXml;

interface

uses
  Forms, SysUtils, Windows, Classes;

const
  open_tag = '<';
  close_tag = '>';
  comment_tag = '!';

type
  TXMLNode = class;
  TXMLNodeArr = array of TXMLNode;

  TXMLNode = class( TObject )
  private
    m_Lines       : TStringList; //Stored Info for the current level of the node.

    m_Name        : string;
    m_Value       : string;
    m_NodeID      : integer;
    m_NodeCount   : integer;
    m_Nodes       : TXMLNodeArr;
    m_Node        : TXMLNode;
  public
    property Name     : string read m_Name write m_Name;
    property Value    : string read m_Value write m_Value;
    property Nodes    : TXMLNodeArr read m_Nodes write m_Nodes;
    property Node     : TXMLNode read m_Node write m_Node;

    constructor Create();
    destructor Destroy(); override;
    procedure Clear();
    function SetFirstNode():boolean;
    function GetNextNode():boolean;
  end;

  TXMLDoc = class(TXMLNode)
  private
  public
    function LoadFile(nFileName:string):boolean;

  end;

implementation

constructor TXMLNode.Create();
begin
  inherited Create();

  m_Lines := TStringList.Create();
end;

destructor TXMLNode.Destroy();
begin
  FreeAndNil(m_Lines);

  inherited Destroy();
end;

procedure TXMLNode.Clear;
begin
  m_Lines.Clear;
  m_LineIndex  := -1;
  m_Line       := '';
  m_CommentIdent := '!';
end;

function TXMLNode.SetFirstNode():boolean;
begin
  result := FALSE;
  if (m_NodeCount <= 0) then exit;

  m_NodeID := -1;
  result := TRUE;
end;

function TXMLNode.GetNextNode():boolean;
begin
  result := FALSE;

  Inc(m_NodeID);

  if (m_NodeID < m_NodeCount) then
  begin
    m_Node := m_Nodes[m_NodeID];
    result := TRUE;
  end;
end;

//===============================

function TXMLDoc.LoadFile(nFileName:string):boolean;
begin
  result := FALSE;

  if (FileExists(nFilename)) then
  begin
    result := TRUE;

    m_Lines.LoadFromFile(nFileName);
  end;
end;

end.
